﻿using FluentNHibernate.Mapping;
using AdventureWorks.Domain;

namespace AdventureWorks.DataAccess.Mappings
{
    public class ProductMapping : ClassMap<Product>
    {
        public ProductMapping() : base()
        {
            Schema("Production");
            Table("Product");
            Id(x => x.Id, "ProductId").GeneratedBy.Native();
            Map(p => p.Name);
            Map(p => p.ProductNumber);
            Map(p => p.MakeFlag);
            Map(p => p.FinishedGoodsFlag);
            Map(p => p.Color);
            Map(p => p.SafetyStockLevel);
            Map(p => p.ReorderPoint);
            Map(p => p.StandardCost);
            Map(p => p.ListPrice);
            Map(p => p.SellEndDate);
            Map(p => p.SellStartDate);
            Map(p => p.Size);
            Map(p => p.SizeUnitMeasureCode);
            Map(p => p.Weight);
            Map(p => p.WeightUnitMeasureCode);
            Map(p => p.DaysToManufacture);
            References(p => p.SubCategory, "ProductSubCategoryId");
            /*HasMany<PriceHistoryItem>(x => x.ProductPriceHistory)
                .KeyColumn("ProductId").Table("ProductListPriceHistory").Schema("Production")
                .Component(y =>
                {
                    y.Map(z => z.StartDate);
                    y.Map(z => z.ListPrice);
                    y.Map(z => z.EndDate);
                });
            HasManyToMany<ProductPhoto>(x => x.Photos)
                .Table("ProductProductPhoto").Schema("Production")
                .ParentKeyColumn("ProductId").ChildKeyColumn("ProductPhotoId");
              */
            HasMany<ProductReview>(x => x.Reviews).KeyColumn("ProductId");
        }
    }
}